package com.ruoyi.web.controller.note;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.note.domain.TBookKey;
import com.ruoyi.note.service.ITBookKeyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 词条Controller
 * 
 * @author cl
 * @date 2021-05-31
 */
@RestController
@RequestMapping("/book/key")
public class TBookKeyController extends BaseController
{
    @Autowired
    private ITBookKeyService tBookKeyService;

    /**
     * 查询词条列表
     */
    @PreAuthorize("@ss.hasPermi('book:key:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBookKey tBookKey)
    {
        startPage();
        List<TBookKey> list = tBookKeyService.selectTBookKeyList(tBookKey);
        return getDataTable(list);
    }

    /**
     * 导出词条列表
     */
    @PreAuthorize("@ss.hasPermi('book:key:export')")
    @Log(title = "词条", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TBookKey tBookKey)
    {
        List<TBookKey> list = tBookKeyService.selectTBookKeyList(tBookKey);
        ExcelUtil<TBookKey> util = new ExcelUtil<TBookKey>(TBookKey.class);
        return util.exportExcel(list, "词条数据");
    }

    /**
     * 获取词条详细信息
     */
    @PreAuthorize("@ss.hasPermi('book:key:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tBookKeyService.selectTBookKeyById(id));
    }

    /**
     * 新增词条
     */
    @PreAuthorize("@ss.hasPermi('book:key:add')")
    @Log(title = "词条", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBookKey tBookKey)
    {
        return toAjax(tBookKeyService.insertTBookKey(tBookKey));
    }

    /**
     * 修改词条
     */
    @PreAuthorize("@ss.hasPermi('book:key:edit')")
    @Log(title = "词条", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBookKey tBookKey)
    {
        return toAjax(tBookKeyService.updateTBookKey(tBookKey));
    }

    /**
     * 删除词条
     */
    @PreAuthorize("@ss.hasPermi('book:key:remove')")
    @Log(title = "词条", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tBookKeyService.deleteTBookKeyByIds(ids));
    }
}
